<?php
/**
 * Created by PhpStorm.
 * User: 胡毅  Mrmj  美容美甲
 * Date: 2016/1/24
 * Time: 1:28
 */
class MrmjAction extends Action{
    public function mrmj(){
        $this->display('mrmj');
    }
    /*
    *  mr_1
    */
    public function mr_1(){
        $model=M("user");
        if(isset($_SESSION['phone'])){
        $phone=$_SESSION['phone'];
        $info=$model->where("phone=".$phone )->find();
        $_SESSION['pId']=$info['pId'];  //把查询到的手机号码用户id存入session
        $pidList=$info['pId'];
            $mr_1='04.png';//固定了图片
        $sql1="select id,yhpic from pics where id not in($pidList) and yhpic='$mr_1'";  //查询用户没使用图片的id    uId in($uid) or
       // $sql2="select id,yhpic from pics where id in($pidList)";     //查询用户使用过的图片
     //   $images2=M("pics")->query($sql2);
        $images= M("pics")->query($sql1);
        $this->assign("info",$info);
        $this->assign("images",$images[0]);//查询用户没使用图片
        }
        $this->display('mr_1');
    }
    //检测手机号码   用户没有登陆的状态下
    public function check_1(){
       if(isset($_POST['button2'])){
            $model=M("user");
            $phone=$_POST['phone'];
            $mr_1='04.png';
            $_SESSION['phone']=$_POST['phone'];
            $info=$model->where("phone=".$phone)->find();
            if($info){
                $_SESSION['pId']=$info['pId'];  //把查询到的手机号码用户id存入session
                $pidList=$info['pId'];
                $sql1="select id,yhpic from pics where id not in($pidList) and yhpic='$mr_1'";   //查询用户没使用图片的id    uId in($uid) or

                $images= M("pics")->query($sql1);
                $this->assign("info",$info);
                $this->assign("images",$images[0]);//查询用户没使用图片
                $this->display("mr_1");
            }else{
                $this->redirect("Mrmj/mr_1");exit;
            }
        }else{
            $this->redirect("Mrmj/mr_1");
       }
    }
    /*
   *  mr_    没有数据分配的页面
   */
    public function mr_2(){
        $this->display('mr_2');
    }
    public function mr_4(){
        $this->display('mr_4');
    }
    public function mr_5(){
        $this->display('mr_5');
    }
    public function mr_6(){
        $this->display('mr_6');
    }
    public function mr_8(){
        $this->display('mr_8');
    }
    public function mr_9(){
        $this->display('mr_9');
    }
    /*
      *  mr_ 7   数据分配的页面
      */
    public function mr_7(){
        $model=M("user");
        if(isset($_SESSION['phone'])) {
            $phone = $_SESSION['phone'];
            $mr_7 = 'dmn05.png';
            $info = $model->where("phone=" . $phone)->find();
            $_SESSION['pId'] = $info['pId'];  //把查询到的手机号码用户id存入session
            $pidList = $info['pId'];
            $sql1 = "select id,yhpic from pics where id not in($pidList) and yhpic='$mr_7'";  //查询用户没使用图片的id    uId in($uid) or
            $images = M("pics")->query($sql1);
            $this->assign("info", $info);
            $this->assign("images", $images[0]);//查询用户没使用图片
        }
        $this->display('mr_7');
    }
    //检测手机号码   用户没有登陆的状态下
    public function check_7(){
        if(isset($_POST['button2'])){
            $model=M("user");
            $phone=$_POST['phone'];
            $mr_7='dmn05.png';
            $_SESSION['phone']=$_POST['phone'];
            $info=$model->where("phone=".$phone)->find();
            if($info){
                $_SESSION['pId']=$info['pId'];  //把查询到的手机号码用户id存入session
                $pidList=$info['pId'];
                $sql1="select id,yhpic from pics where id not in($pidList) and yhpic='$mr_7'";   //查询用户没使用图片的id    uId in($uid) or

                $images= M("pics")->query($sql1);
                $this->assign("info",$info);
                $this->assign("images",$images[0]);//查询用户没使用图片
                $this->display("mr_7");
            }else{
                $this->redirect("Mrmj/mr_7");exit;
            }
        }else{
            $this->redirect("Mrmj/mr_7");
        }
    }
    //确定使用优惠券后改变状态入库----------------------共享开始--------------------------------------------------
    public function hit(){
        $model=M('user');
        $pid=$_GET['pid'];
        $uid=$_GET['uid'];  //将图片id放入用户id
        $pids=$model->where("id=".$uid)->field('pId')->find();
        $pidList=$pids['pId'].','.$pid;
        $data=array(
            'id'=>$uid,
            'pId'=>trim($pidList,','),
        );
        if($model->save($data)) {
            $this->ajaxReturn("使用成功");
        }else{
            $this->ajaxReturn("使用失败");
        }
    }
    //------------------------------共享结束------------------------------------------------------------------------------
}